package com.share.thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @desc:
 * @author:caifan
 * @date:2022/3/25
 */
public class ThreadLocalDemo03 {

    public static ExecutorService threadPool = Executors.newFixedThreadPool(16);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");

    public static void main(String[] args) throws InterruptedException {
        ThreadLocalDemo03 threadLocalDemo03 = new ThreadLocalDemo03();
        for (int i = 1; i <= 1000; i++) {

            threadPool.submit(() -> {
                try {
                    boolean valid = threadLocalDemo03.date();
                    System.out.println(valid);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });

        }
//        Thread.sleep(1000);
        threadPool.shutdown();
    }

    public boolean date() throws ParseException  {
        Date date = new Date();
        String str = format.format(date);
        Date date1 = format.parse(str);
        String str2 = this.format.format(date1);
        return str.equals(str2);
    }
}
